import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import { viteMockServe } from "vite-plugin-mock";
import ViteComponents, { AntDesignVueResolver } from "vite-plugin-components";

const localEnabled = process.env.USE_MOCK || false;

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    host: "0.0.0.0",
    open: true,
    proxy: {},
  },
  build: {
    rollupOptions: {
      output: {
        manualChunks: {
          // 'echarts': ['echarts']
        },
      },
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
      "@view": path.resolve(__dirname, "src/view"),
      "@assets": path.resolve(__dirname, "src/assets"),
      "@components": path.resolve(__dirname, "src/components"),
      "@hooks": path.resolve(__dirname, "src/hooks"),
      "@router": path.resolve(__dirname, "src/router"),
      "@store": path.resolve(__dirname, "src/store"),
      "@utils": path.resolve(__dirname, "src/utils"),
      "@layout": path.resolve(__dirname, "src/layout"),
      "@services": path.resolve(__dirname, "src/services"),
      "@config": path.resolve(__dirname, "src/config"),
      "@pinia": path.resolve(__dirname, "src/pinia"),
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  envDir: './env',
  envPrefix: ['VITE_','VUE_'],
  plugins: [
    vue(),
    // ViteComponents({
    //   customComponentResolvers: [AntDesignVueResolver()],
    // }),
    viteMockServe({
      mockPath: "./src/mock", //mock文件地址
      localEnabled: localEnabled, // 开发打包开关
      prodEnabled: false, // 生产打包开关
      // 这样可以控制关闭mock的时候不让mock打包到最终代码内
      injectCode: `
        import { setupProdMockServer } from './src/mockProdServer';
        setupProdMockServer();
      `,
      logger: true, //是否在控制台显示请求日志
      supportTs: false, //打开后，可以读取 ts 文件模块。 请注意，打开后将无法监视.js 文件
    }),
  ],
});
